package cn.edu.njust.service.impl;

import cn.edu.njust.mapper.UserMapper;
import cn.edu.njust.pojo.User;
import cn.edu.njust.service.ChangeService;
import cn.edu.njust.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class ChangeServiceImpl implements ChangeService {

    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public void changeUser(User user, String idNo) {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        //获取数据
        String email = user.getEmail();
        String telephone = user.getTelephone();
        String password = user.getPassword();

        //调用方法
        mapper.changeUseremail(email, idNo);
        mapper.changeUsertelephone(telephone, idNo);
        mapper.changeUserpassword(password, idNo);

        sqlSession.commit();

        sqlSession.close();
    }
}
